package com.yxe.serializer;

import cn.hutool.core.date.DateUtil;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.yxe.pojo.Pay;

import java.io.IOException;

public class PaySerializer extends JsonSerializer<Pay> {
    @Override
    public void serialize(Pay value, JsonGenerator generator, SerializerProvider serializers) throws IOException {

        generator.writeStartObject();//开始写入

        generator.writeNumberField("payId", value.getPayId());
        generator.writeStringField("payType", value.getPayType().getDescription());
        generator.writeNumberField("payMoney", value.getPayMoney());
        generator.writeStringField("payMonth", DateUtil.format(value.getPayMonth(), "yyyy-MM-dd"));
        generator.writeNumberField("userId", value.getUserId());

        generator.writeEndObject();//结束
    }
}